package cn.kpi.service.workassessment.impl;

import cn.kpi.dao.workassessment.GRightsDao;
import cn.kpi.dao.workassessment.GroupDao;
import cn.kpi.entity.workassessment.GroupEntity;
import cn.kpi.service.workassessment.IGroupService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class GroupServiceImpl implements IGroupService {
    @Autowired
    private GroupDao groupDao;


    @Autowired
    private GRightsDao grightsDao;

    public List<GroupEntity> GetGroupList(String where) {
        try {
            return groupDao.GetGroupList(where);
        } catch (Exception ex) {
            ex.printStackTrace();
            return null;
        }
    }

    public int GetGroupListCount(String where) throws Exception {
        try {
            return groupDao.GetGroupListCount(where);
        } catch (Exception ex) {
            ex.printStackTrace();
            return -1;
        }
    }

    public int InsertEntity(GroupEntity entity) throws Exception {
        try {
            return groupDao.InsertEntity(entity);
        } catch (Exception ex) {
            ex.printStackTrace();
            return -1;
        }
    }

    public int UpdateEntity(GroupEntity entity) throws Exception {
        try {
            grightsDao.updateGroupOrgOrder(entity.getGroupid());
            return groupDao.UpdateEntity(entity);
        } catch (Exception ex) {
            ex.printStackTrace();
            return -1;
        }
    }

    public int DeleteEntity(Long groupid) throws Exception {
        try {
            groupDao.DeleteGroup(groupid);
            return groupDao.DeleteEntity(groupid);
        } catch (Exception ex) {
            ex.printStackTrace();
            return -1;
        }
    }

    public List<GroupEntity> GetGroupListLimit(String where, String order, int beginrow, int endrow) throws Exception {
        try {
            return groupDao.GetGroupListLimit(where, order, beginrow, endrow);
        } catch (Exception ex) {
            ex.printStackTrace();
            return null;
        }
    }
}
